let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    var order_id=options.order_id;
    if(order_id==undefined){
      this.showModels('订单错误','#','#');
    }else if(order_id==''){
      this.showModels('订单错误','#','#');
    }else{
      this.setData({
        order_id:order_id
      })
      this.getOrder(order_id);
    }
    this.setData({
     domain:app.globalData.domain,
     width:app.globalData.windowWidth,
      height:app.globalData.windowHeight,
      statusBarHeight:app.globalData.statusBarHeight,
      navHeight:app.globalData.navHeight,
      marginTop:app.globalData.navTitleTop
    })
  },
 getOrder(order_id){
   let that=this;
   var open=wx.getStorageSync('open');
   console.log(open);
  var open_id=open.id;
   wx.request({
    // url: 'https://lypb.com/lupao/enrolls.php',
     url: app.globalData.domain+'match/order/getOrder',
     header: {
       'Content-Type': 'application/x-www-form-urlencoded',
     },
     data: { 
   
           from:1, 
           open_id:open.id,
           order_id:order_id,
          
       },
     success:function(res){
         console.log(res);
         var data=res.data;
         that.setData({
           match:data.match,
           order:data.order,
           type:data.type
         })
       
     },
     fail:function(res){

     }
   })


 },
 orderPay:function(){
  var that=this;
  var order_id=this.data.order_id;
  var open=wx.getStorageSync('open');
  wx.request({
    url:app.globalData.domain+'match/match/Pay',    
    data: {order_id: order_id, open_id: open.id, openid: open.mini_openid,type:1 },
    success: function (res) {
     console.log(res.data);
      //console.log('调起支付');
      var code=res.data.code;
      if(code==200){
      var data=res.data.data;
        wx.requestPayment({
            'timeStamp': data.timeStamp,
            'nonceStr': data.nonceStr,
            'package': data.package,
            'signType': 'MD5',
            'paySign': data.paySign,
            'success': function (res) {
             // console.log('success');
              wx.showToast({
                title: '支付成功',
                icon: 'success',
                duration: 3000
              });
              setTimeout(function() {
                  //要延时执行的代码
                  wx.navigateTo({
                    url: '/pages/mine/order?id=1',
                  })
                }, 1000) //延迟时间
              //that.waitPayShow();
            },
            'fail': function (res) {
              //console.log(res);
            },
            'complete': function (res) {
             // console.log('complete');
            }
          });
      }else{

      }
  
    },
    fail: function (res) {
      //console.log("fail")
    }
  }); 

},
orderCancle:function(){
  var that=this;
  var order_id=this.data.order_id;
  var open=wx.getStorageSync('open');
  wx.showModal({
    title: '系统提示',
    content: '您确定要取消订单么',
    complete: (res) => {
    
      if (res.confirm) {

          wx.request({
          url:app.globalData.domain+'match/match/orderCancel',
          data:{id:order_id,open_id:open.id},
          success:function(res){
            //console.log(res);
            if(res.data.code==200){
                that.getOrder(order_id)
            }
          }
        })
       
      }
    }
  })
},
 goBack:function(){
  wx.navigateBack();
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})